fix: respect SentryNative=false at runtime#4220
Merged
bruno-garcia merged 2 commits intomainfrom May 26, 2025
Merged
Conversation
-p:SentryNative=false at runtimeSentryNative=false at runtime
Collaborator
Author
|
The Subsequently, when the runtime host configuration option was undefined at runtime, it would default to sentry-dotnet/src/Sentry/Platforms/Native/SentryNative.cs Lines 10 to 20 in b97aec8 Manual steps for reproducing the problem: $ dotnet new console -o HelloWorld --aot
[...]
$ cd HelloWorld/
$ dotnet add package Sentry -v 5.8.0
[...]
$ cat > Program.cs <<'EOF'
SentrySdk.Init(options =>
{
options.Dsn = "https://foo@sentry.invalid/42";
options.Debug = true;
});
Console.WriteLine("Hello, Sentry!");
EOF
$ dotnet publish -p:SentryNative=false
Restore complete (0.3s)
HelloWorld succeeded (10.0s) → bin/Release/net9.0/linux-x64/publish/
Build succeeded in 10.5s
Workload updates are available. Run `dotnet workload list` for more information.
$ ./bin/Release/net9.0/linux-x64/publish/HelloWorld
Debug: Logging enabled with ConsoleDiagnosticLogger and min level: Debug
Warning: Sentry option 'Debug' is set to true while Environment is production. Be aware this can cause performance degradation and is not advised. See https://docs.sentry.io/platforms/dotnet/configuration/diagnostic-logger for more information
Debug: This looks like a Native AOT application build.
Unhandled exception. System.DllNotFoundException: Unable to load shared library 'sentry-native' or one of its dependencies. In order to help diagnose loading problems, consider using a tool like strace. If you're using glibc, consider setting the LD_DEBUG environment variable:
sentry-native.so: cannot open shared object file: No such file or directory
libsentry-native.so: cannot open shared object file: No such file or directory
sentry-native: cannot open shared object file: No such file or directory
libsentry-native: cannot open shared object file: No such file or directory
at System.Runtime.InteropServices.NativeLibrary.LoadLibErrorTracker.Throw(String) + 0x46
at Internal.Runtime.CompilerHelpers.InteropHelpers.FixupModuleCell(InteropHelpers.ModuleFixupCell*) + 0x139
at Internal.Runtime.CompilerHelpers.InteropHelpers.ResolvePInvokeSlow(InteropHelpers.MethodFixupCell*) + 0x35
at Sentry.Native.C.sentry_options_new() + 0x1f
at Sentry.Native.C.Init(SentryOptions) + 0x1f
at Sentry.SentrySdk.InitNativeSdk(SentryOptions) + 0x2d
at Sentry.SentrySdk.InitHub(SentryOptions) + 0x190
at Sentry.SentrySdk.Init(Action`1) + 0x3a
at Program.<Main>$(String[] args) + 0x51
Aborted (core dumped)runtimeconfig.json (SentryNative=true => "Sentry.Native.IsEnabled": true)$ dotnet publish -p:SentryNative=true
Restore complete (0.2s)
HelloWorld succeeded (8.6s) → bin/Release/net9.0/linux-x64/publish/
Build succeeded in 8.9s
Workload updates are available. Run `dotnet workload list` for more information.
$ cat ./bin/Release/net9.0/linux-x64/HelloWorld.runtimeconfig.json{
"runtimeOptions": {
"tfm": "net9.0",
"includedFrameworks": [
{
"name": "Microsoft.NETCore.App",
"version": "9.0.4"
}
],
"configProperties": {
"Sentry.Native.IsEnabled": true,
"Microsoft.Extensions.DependencyInjection.VerifyOpenGenericServiceTrimmability": true,
"System.ComponentModel.DefaultValueAttribute.IsSupported": false,
"System.ComponentModel.Design.IDesignerHost.IsSupported": false,
"System.ComponentModel.TypeConverter.EnableUnsafeBinaryFormatterInDesigntimeLicenseContextSerialization": false,
"System.ComponentModel.TypeDescriptor.IsComObjectDescriptorSupported": false,
"System.Diagnostics.Tracing.EventSource.IsSupported": false,
"System.Globalization.Invariant": true,
"System.Globalization.PredefinedCulturesOnly": true,
"System.Net.Security.UseManagedNtlm": false,
"System.Reflection.Metadata.MetadataUpdater.IsSupported": false,
"System.Resources.ResourceManager.AllowCustomResourceTypes": false,
"System.Resources.UseSystemResourceKeys": false,
"System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeSupported": false,
"System.Runtime.InteropServices.BuiltInComInterop.IsSupported": false,
"System.Runtime.InteropServices.EnableConsumingManagedCodeFromNativeHosting": false,
"System.Runtime.InteropServices.EnableCppCLIHostActivation": false,
"System.Runtime.InteropServices.Marshalling.EnableGeneratedComInterfaceComImportInterop": false,
"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false,
"System.StartupHookProvider.IsSupported": false,
"System.Text.Encoding.EnableUnsafeUTF7Encoding": false,
"System.Text.Json.JsonSerializer.IsReflectionEnabledByDefault": false,
"System.Threading.Thread.EnableAutoreleasePool": false,
"System.Linq.Expressions.CanEmitObjectArrayDelegate": false
}
}
}runtimeconfig.json (SentryNative=false => N/A)$ dotnet publish -p:SentryNative=false
Restore complete (0.2s)
HelloWorld succeeded (8.3s) → bin/Release/net9.0/linux-x64/publish/
Build succeeded in 8.6s
Workload updates are available. Run `dotnet workload list` for more information.
$ cat ./bin/Release/net9.0/linux-x64/HelloWorld.runtimeconfig.json{
"runtimeOptions": {
"tfm": "net9.0",
"includedFrameworks": [
{
"name": "Microsoft.NETCore.App",
"version": "9.0.4"
}
],
"configProperties": {
"Microsoft.Extensions.DependencyInjection.VerifyOpenGenericServiceTrimmability": true,
"System.ComponentModel.DefaultValueAttribute.IsSupported": false,
"System.ComponentModel.Design.IDesignerHost.IsSupported": false,
"System.ComponentModel.TypeConverter.EnableUnsafeBinaryFormatterInDesigntimeLicenseContextSerialization": false,
"System.ComponentModel.TypeDescriptor.IsComObjectDescriptorSupported": false,
"System.Diagnostics.Tracing.EventSource.IsSupported": false,
"System.Globalization.Invariant": true,
"System.Globalization.PredefinedCulturesOnly": true,
"System.Net.Security.UseManagedNtlm": false,
"System.Reflection.Metadata.MetadataUpdater.IsSupported": false,
"System.Resources.ResourceManager.AllowCustomResourceTypes": false,
"System.Resources.UseSystemResourceKeys": false,
"System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeSupported": false,
"System.Runtime.InteropServices.BuiltInComInterop.IsSupported": false,
"System.Runtime.InteropServices.EnableConsumingManagedCodeFromNativeHosting": false,
"System.Runtime.InteropServices.EnableCppCLIHostActivation": false,
"System.Runtime.InteropServices.Marshalling.EnableGeneratedComInterfaceComImportInterop": false,
"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false,
"System.StartupHookProvider.IsSupported": false,
"System.Text.Encoding.EnableUnsafeUTF7Encoding": false,
"System.Text.Json.JsonSerializer.IsReflectionEnabledByDefault": false,
"System.Threading.Thread.EnableAutoreleasePool": false,
"System.Linq.Expressions.CanEmitObjectArrayDelegate": false
}
}
} |
ccb7e24 to
d33c54a
Compare
d33c54a to
a8fbd22
Compare
jpnurmi
commented
May 26, 2025
bruno-garcia
approved these changes
May 26, 2025
This was referenced Aug 18, 2025
This was referenced Sep 8, 2025
This was referenced Sep 15, 2025
This was referenced Oct 6, 2025
This was referenced Nov 3, 2025
This was referenced Dec 8, 2025
This was referenced Dec 15, 2025
This was referenced Jan 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes the problem that
<SentryNative>false</SentryNative>results inSentry.Native.IsEnabled=trueat runtime, as it came up in: